package carddemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yinsh
 * Date: 2025-01-20
 * Time: 21:31
 */
public class CardList {
    private String[] suits = {"♣", "♥", "♦", "♠"};
    private List<Card> cards = new ArrayList<>(52);
    public CardList() {
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                cards.add(new Card(i, suits[j]));
            }
        }
    }
    public static void swap(List<Card> cards) {
        Random random = new Random();
        for (int i = 51; i > 0; i--) {
            Card tamp = cards.get(i);
            int ran = random.nextInt(i);
            cards.set(i,cards.get(ran));
            cards.set(ran,tamp);
        }

    }
    public static List<List<Card>> dealCards(List<Card> cards) {
        List<List<Card>> hands = new ArrayList<>(3);
        List<Card> hand1 = new ArrayList<>(13);
        List<Card> hand2 = new ArrayList<>(13);
        List<Card> hand3 = new ArrayList<>(13);

        for (int i = 0; i < 51; i++) {
            hand1.add(cards.get(i));
            i++;
            hand2.add(cards.get(i));
            i++;
            hand3.add(cards.get(i));
        }
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        return hands;
    }
    public static void main(String[] args) {
        CardList cardList = new CardList();
        swap(cardList.cards);
        System.out.println(cardList.cards);
        System.out.println(dealCards(cardList.cards));
    }
}






